/*
 * @Author: xiaosihan 
 * @Date: 2021-05-09 11:28:33 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2021-11-07 02:25:52
 */

import events from "events";
import { MathUtils } from "three";

export default class Emit extends events {
    constructor() {
        super();
    }

    id = MathUtils.generateUUID();

    // 分发事件
    emit(eventName: string, ...arg: any) {
        super.emit(eventName, arg);
        return false;
    }

    // 添加监听
    on(eventName: string, callback: (...args: any[]) => void) {

        //避免重复监听
        super.off(eventName, callback);
        // 添加监听事件
        super.on(eventName, callback);
        return this;
    }

    // 添加一次性的监听
    once(eventName: string, callback: (...args: any[]) => void) {
        //避免重复监听
        super.off(eventName, callback);
        // 添加监听事件
        super.once(eventName, callback);
        return this;
    }

    // 取消监听
    off(eventName: string, callback: (...args: any[]) => void) {
        super.off(eventName, callback);
        return this;
    }

    BEFORE_RENDER = "before_Render";

    AFTER_RENDER = "after_Render";
}